package ioc

import (
	"fmt"

	"github.com/gin-gonic/gin"
)

func (app *Container) SetApi(obj ApiIocObj) {
	app.apis[obj.Name()] = obj
}
func (app *Container) GetApi(name string) ApiIocObj {
	v, ok := app.apis[name]
	if !ok {
		panic(fmt.Sprintf("api not found: %s", name))
	}
	return v
}

func (app *Container) InitApi(r gin.IRouter) error {
	for _, v := range app.apis {
		if err := v.Init(); err != nil {
			return err
		}
		v.Register(r)
	}
	return nil
}
